package com.young.mbgdiy.config;

import org.mybatis.generator.api.dom.xml.XmlElement;
import org.mybatis.generator.config.Context;
import org.mybatis.generator.config.ModelType;

import java.util.List;

/**
 * TODO
 *
 * @author ：<a href="mailto:youngkun2016@163.com">young</a>
 * @date ：Created in 2020/4/5
 */
public class ContextOverride extends Context {
    /**
     * 添加ServiceGeneratorConfiguration
     */
    private ServiceGeneratorConfiguration serviceGeneratorConfiguration;

    public ContextOverride(ModelType defaultModelType) {
        super(defaultModelType);
    }

    public ServiceGeneratorConfiguration getServiceGeneratorConfiguration() {
        return serviceGeneratorConfiguration;
    }

    public void setServiceGeneratorConfiguration(ServiceGeneratorConfiguration serviceGeneratorConfiguration) {
        this.serviceGeneratorConfiguration = serviceGeneratorConfiguration;
    }

    @Override
    public void validate(List<String> errors) {
        if (serviceGeneratorConfiguration != null) {
            serviceGeneratorConfiguration.validate(errors, this.getId());
        }

        super.validate(errors);
    }

    @Override
    public XmlElement toXmlElement() {

        XmlElement xmlElement = super.toXmlElement();
        if (serviceGeneratorConfiguration != null) {
            xmlElement.addElement(serviceGeneratorConfiguration.toXmlElement());
        }
        return xmlElement;
    }
}